package com.sbr.seb.rule;

import java.util.List;

import com.sbr.genericdao.DAO;
import com.sbr.seb.rule.entity.PersistedSpecification;
import com.sbr.seb.rule.exception.SpecificationException;

public class Rule<T> {

	private List<PersistedSpecification> specifications;
	private DAO<PersistedSpecification> dao;


	public void init() {
		specifications = dao.findAll();
	}

	public boolean checkSpecifications(T candidate) throws SpecificationException {
		boolean isSatisfied = true;
		for (PersistedSpecification spec : specifications) {
			if (!spec.isSatisfiedBy(candidate)) {
				isSatisfied = false;
			}
		}
		return isSatisfied;
	}

	public void setDao(DAO<PersistedSpecification> dao) {
		this.dao = dao;
	}

}
